package com.jbit.dm212.service.impl;

import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.jbit.dm212.entity.dto.DmSchedulerSeatPriceDTO;
import com.jbit.dm212.entity.po.DmSchedulerSeat;
import com.jbit.dm212.entity.po.DmSchedulerSeatPrice;
import com.jbit.dm212.mapper.DmSchedulerSeatPriceMapper;
import com.jbit.dm212.service.DmSchedulerSeatPriceService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class DmSchedulerSeatPriceServiceImpl implements DmSchedulerSeatPriceService {
    @Resource
    private DmSchedulerSeatPriceMapper schedulerSeatPriceMapper;
    @Override
    public List<DmSchedulerSeatPriceDTO> getPricesByScheduleId(Integer scheduleId) {
        MPJLambdaWrapper<DmSchedulerSeatPrice> lambdaWrapper = new MPJLambdaWrapper<>();


        lambdaWrapper.selectSub(DmSchedulerSeat.class,wrapper->{
            wrapper.eq(DmSchedulerSeat::getScheduleId,scheduleId)
                    .eq(DmSchedulerSeat::getStatus,1)
                    .eq(DmSchedulerSeat::getAreaLevel,DmSchedulerSeatPrice::getAreaLevel)
                    .selectCount(DmSchedulerSeat::getId);
        },DmSchedulerSeatPriceDTO::getIsHaveSeat);

        lambdaWrapper.select(
                DmSchedulerSeatPrice::getId,
                DmSchedulerSeatPrice::getScheduleId,
                DmSchedulerSeatPrice::getPrice
        );
        lambdaWrapper.eq(DmSchedulerSeatPrice::getScheduleId,scheduleId);
        List<DmSchedulerSeatPriceDTO> list = schedulerSeatPriceMapper.selectJoinList(DmSchedulerSeatPriceDTO.class,lambdaWrapper);
        list.forEach(seatPrice->seatPrice.setIsHaveSeat(seatPrice.getIsHaveSeat() > 0 ? 1 : 0));
        return list;
    }
}
